﻿/**
 * RichTextField
 * @copyright www.riaidea.com
 * @author Alex.li (flashlizi@gmail.com)
 * @version 0.1
 */

package as3.component.controls
{	
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	import flash.utils.*;
	
	
	public class RichTextField extends Sprite
	{
		
		
		//the instance of textfield
		private var _textfield:TextField;
		private var _textArr:Array = new Array();
		//the default textformat of _textfield
		private var _defaultTextFormat:TextFormat;
		//the length of the _textfield.text
		private var _length:int;
		//only contain sprites which are inserted in _textfield
		private var _spriteContainer:Sprite;
		private var _spriteNum:int;
		
		private var imgArr:Array = new Array();
		
		//specify the sprite's vspace/hspace in _textfield
		private var _spriteVspace:int;
		private var _spriteHspace:int;
		//save the scrollV of the _textfield
		private var _scrollV:int;		
		//the mask of _spriteContainer
		private var _spriteMask:Shape;
		//use it to mark the TextField.replaceText() time during addSprite
		private var _replacing:Boolean;
		
		//indicates whether the textfield scroll to the bottom line automatically.
		public var autoScroll:Boolean = true;
		public var autoScrollV:int = 0;
		//indicates line height.
		public var lineHeight:Number;
		
		//specify type of _textfield
		public static const DYNAMIC:String = "dynamic";
		public static const INPUT:String = "input";
		
		/**
		 * trick, a sprite's placeholder
		 * special character: ﹒ unicode is 65106
		 * special font: Arial
		 */
		//private var PLACEHOLDER:String = String.fromCharCode(65106);
		private var PLACEHOLDER:String = "﹒";
		private var PLACEHOLDER_FONT:String = "Arial";
		private var PLACEHOLDER_COLOR:uint = 0x000000;
		
		//type of adjust
		private static const ADJUST_TYPE_INSERT:String = "adjust_type_insert";
		private static const ADJUST_TYPE_CHANGE:String = "adjust_type_change";		
		private var _defaultFormat:TextFormat;
		private var _color:uint = 0xffffff;
		private var _fontSize:uint = 2;
		private var _bold:Boolean = false;
		private var _italic:Boolean = false;
		private var _underLine:Boolean = false;
		private var _fontName:String = "宋体";
		private var _algin:String = TextFormatAlign.LEFT;
		private var _leading:Number = 0;
		
		/**
		 * constructor
		 */
		public function RichTextField(width:Number, height:Number)
		{
			initTextField(width, height);			
			addChild(_textfield);
			_textfield.addEventListener(Event.SCROLL, scrollHandler);
			
			
			_spriteContainer = new Sprite();
			addChild(_spriteContainer);			
			//default scrollV is 1
			_scrollV = 1;
			//default lineHeight is 0(ignore)
			lineHeight = 0;
			//default sprite vspace/hspace is 2 (changes to 1, 2009-3-3)
			_spriteHspace = _spriteVspace = 1;		
			_spriteMask = createSpritesMask(_textfield.x, _textfield.y, _textfield.width, _textfield.height);
			addChild(_spriteMask);
			_spriteContainer.mask = _spriteMask;
		}		
		
		
		// ********************** public method *********************************	
		
		/**
		 * append rich text which contains display objects and text format.		 * 
		 * @param	text
		 * @param	object each element should like this {index:1, src:object}
		 * @param	format
		 * @param	autoWordWrap
		 */
		public function appendRichText(text:String, autoWordWrap:Boolean = true):void
		{
			var tempText:TextField = new TextField();
			tempText.htmlText = text;
			for(var i:int = 0;i<text.length - 2;i++)
			{
				if(text.charAt(i)=="/"&&imgstrToClass(text.substr(i,3)))
				{
					text = text.replace(text.substr(i,3),"");
					i -= 1;
				}
			}
			appendText(text, autoWordWrap);
			text = tempText.text;
			for(var i2:int = 0;i2<text.length - 2;i2++)
			{
				if(text.charAt(i2)=="/"&&imgstrToClass(text.substr(i2,3)))
				{
					var c:String = text.substr(i2,3);
					text = text.replace(text.substr(i2,3),"");
					i2 -= 1;
				}
			}
			for(var j:int = 0;j<tempText.text.length - 2;j++)
			{
				if(tempText.text.charAt(j)!="/")
				{
					continue;
				}
				var imgstr:String = tempText.text.substr(j,3);
				if(imgstrToClass(imgstr))
				{
					var index:int = j;
					if (index == -1)
					{ 
						index = tempText.text.length;
					}
					else if (autoWordWrap)
					{
						index -= 1;
					}
					index += _textfield.length - text.length;
					
					var newImg:Object = new Object();
					newImg.imgstr = imgstr;
					newImg.index = j;
					newImg.y = -1;
					imgArr.push(newImg);
					
					addSprite(imgstrToClass(imgstr), index, -1, lineHeight,imgArr);
					tempText.text = tempText.text.replace(imgstr,"");
					j -= 1;
				}
			}
			_spriteNum = numSprite;
			if (autoScroll) _textfield.scrollV = _textfield.maxScrollV;	
			else if(autoScrollV > 0) _textfield.scrollV = autoScrollV;
		}
		
		
		public function appendText(text:String, autoWordWrap:Boolean = true):void
		{
			recoverDefaultTextFormat();
			var addText:String = text;
			//because the carriage return escape character(\r) has some bug in text copying
			//so change all of them to newline escape character(\n)	
//			var tempString:String=_textfield.htmlText;
//			tempString = tempString.replace("<FONT COLOR=\"#000000\"></FONT>","");
//			var c:int = tempString.length;
			_textfield.htmlText += addText;
//			var tempString2:String=_textfield.htmlText;
//			tempString2 = tempString2.replace("<FONT COLOR=\"#000000\"></FONT>","");
//			var d:int = tempString2.length;
//			_textArr.push(tempString2.length - tempString.length);
//			if(_textArr.length>2)
//			{
//				var str:String = tempString2.substring(_textArr[0],d);
//				var f:int = str.length;
//				
//				var str4:String = tempString2.substring(0,_textArr[0]);
//				
//				
//				_textfield.htmlText = tempString2.substring(_textArr[0],tempString2.length);
//				
//				var str3:String = _textfield.htmlText;
//				var f2:int = str3.length;
//				_textArr.shift();
//			}
//			var e:int = tempString2.length;
			//if (format)_textfield.setTextFormat(format, start, _textfield.length - 1);
		}
		 
		/**
		 * add a sprite with a placeholder to the right place
		 * @param	target Class or Sprite instance
		 * @param	width
		 * @param	height
		 * @param	caretIndex
		 */
		public function addSprite(target:*, caretIndex:int = -1, width:Number = -1, height:Number = -1,imgArr:Array=null):void
		{
			//create a target sprite
			var targetClass:Class;
			var newObj:Sprite;
			if (target is Class)
			{
				targetClass = target;
				var tempObj:Bitmap=new target()as Bitmap;//as Sprite;
				newObj=new Sprite;
				newObj.addChild(tempObj);	
			}else
			{
				//var className:String = getQualifiedClassName(target);
				//targetClass = getDefinitionByName(className) as Class;
				//newObj = new targetClass() as Sprite;
				//newObj.addChild(target as Bitmap);;
				return;
			}
			if (width > 0) newObj.width = width;
			if (height > 0) newObj.height = height;
			//insert a placeholder for target and format it
			if (caretIndex == -1) caretIndex = _textfield.caretIndex;
			//fix the bug that supplied index is out of bound, 11-24-2008
			//if caretIndex is out of bound, add sprite to the end.			
			if (caretIndex > _textfield.length) {
				caretIndex = _textfield.length;
			}
			var format:TextFormat = getPlaceholderFormat(newObj.width, newObj.height);		
			//because if use replaceText method, the TextField will scroll incorrectly(scrollV=1)
			//we don't need to adjust the _spriteContainer's position in this scroll time
			//so use _replacing to split this time			
			_replacing = true;
			var oldScrollV:int = _textfield.scrollV;
			_textfield.replaceText(caretIndex, caretIndex, PLACEHOLDER);
			_textfield.setTextFormat(format, caretIndex);			
			_replacing = false;
			//srcoll back to the correct line.		
			_textfield.scrollV = oldScrollV;			
			_spriteContainer.addChild(newObj);
			newObj.name = String(caretIndex);
			
			_length++;
			//adjust sprite's coordinate
			adjustSprites(caretIndex,imgArr);
			
		}
		
		/**
		 * clear all properties, back to original status.
		 */
		public function clear():void
		{
			_textfield.text = "";
			_length = 0;
			_scrollV = 1;
			_spriteNum = 0;
			recoverDefaultTextFormat();
			_spriteContainer.y = 0;
			imgArr = new Array();
			_textArr = new Array();
			while (_spriteContainer.numChildren > 0)_spriteContainer.removeChildAt(0);
		}
		
		// ********************** private method *********************************
		
		/**
		 * monitor the change of scrollV and adjust the _spriteContainer's coordinate
		 * @param	evt
		 */
		private function scrollHandler(evt:Event):void
		{			
			//if (_textfield.bottomScrollV <= 1) return;
			if (!_replacing&&_textfield.text!="")
			{									
				var scrollDirection:int = _textfield.scrollV > _scrollV ? 1 : -1;
				var begin:int = scrollDirection > 0 ? (_textfield.scrollV - 2) : (_scrollV - 2);
				var end:int = scrollDirection > 0 ? (_scrollV - 2) : (_textfield.scrollV - 2);
				var scrollHeight:Number = 0;
				for (var i:int = begin; i > end; i--)
				{
					scrollHeight += _textfield.getLineMetrics(i).height;						
				}
				_spriteContainer.y -= scrollDirection * scrollHeight;				
				//trace("scroll", scrollDirection, _scrollV, _textfield.scrollV, scrollDirection * scrollHeight);
				
			}
			if (_replacing && _textfield.scrollV == 1) return;
			_scrollV = _textfield.scrollV;
			//trace("set _scrollV", _scrollV);
		}
		
		/**
		 * adjust the position of sprite if need
		 * @param	caretIndex the caret index of the change place
		 * @param	offset whether plus or minus
		 * @type default is ADJUST_TYPE_CHANGE
		 */
		private function adjustSprites(caretIndex:int,imgArr:Array):void
		{			
			var insertStatus:Boolean = true;
			for (var i:int = _spriteNum, len:int = numSprite; i < len; i++)
			{
				var caret:int = getSpriteIndexAt(i);
				var rectPlaceholder:Rectangle = getCharBoundaries(caret);
				if(imgArr[i].y == -1)
				{
					imgArr[i].y = rectPlaceholder.y;
				}
				else if(imgArr[i].y == rectPlaceholder.y)
				{
					continue;
				}
				var adjustObj:Sprite = _spriteContainer.getChildAt(i) as Sprite;
				//trace("rectPlaceholder: " + rectPlaceholder);
				if (adjustObj && rectPlaceholder)
				{																
					//adjust name and coordinate
					//trace("adjustObj", adjustObj, i, caret, caretIndex);
					//adjustObj.name = String(caret);					
					setSpriteCoordinate(adjustObj, rectPlaceholder);	
				}
			}
		}		
		
		
		
		/**
		 * return a textformat for placeholder corresponding to the given width and height.
		 * @param	width
		 * @param	height
		 * @return
		 */
		private function getPlaceholderFormat(width:Number, height:Number):TextFormat
		{
			var format:TextFormat = new TextFormat();
			format.font = PLACEHOLDER_FONT;
			format.color = PLACEHOLDER_COLOR;
			format.size = height + 2 * _spriteVspace;
			format.underline = false;			
			format.letterSpacing = width - height - 2 * _spriteVspace + 2 * _spriteHspace;
			//trace(width, height, format.size, format.letterSpacing);
			return format;
		}		
		
		/**
		 * recover the default textformat
		 */
		private function recoverDefaultTextFormat():void
		{
			if (_defaultTextFormat) _textfield.defaultTextFormat=_defaultFormat;	
		}
		
		/**
		 * set target sprite to the right coordinate, according to the rectangle of it's placeholder
		 * @param	target
		 * @param	rectPlaceholder
		 */
		private function setSpriteCoordinate(target:Sprite, rectPlaceholder:Rectangle):void
		{
			target.x = _spriteContainer.x + rectPlaceholder.left + _spriteHspace;
			target.y = rectPlaceholder.top + rectPlaceholder.height - target.height - _spriteVspace;
			//trace("setSpriteCoordinate", _spriteContainer.y, _textfield.textHeight, rectPlaceholder);
		}
		
		/**
		 * replace the textfield's getCharBoundaries method
		 * get char boundaries in the specify char index
		 * @param	charIndex
		 * @return
		 */
		private function getCharBoundaries(charIndex:int):Rectangle
		{
			var rect:Rectangle = _textfield.getCharBoundaries(charIndex);
			if (!rect)
			{
				//because only display text can get getCharBoundaries in textfield
				//so we should scroll to the line of this PLACEHOLDER first
				//then calculate the boundary of this PLACEHOLDER, scroll back at last
				var objLine:int = _textfield.getLineIndexOfChar(charIndex);
				if (_textfield.bottomScrollV < objLine)
				{
					var oldScrollV:int = _textfield.scrollV;
					_textfield.scrollV = objLine;
					rect = _textfield.getCharBoundaries(charIndex);
					_textfield.scrollV = oldScrollV;
				}
			}
			if(rect)
			{
				rect.y += 4;
			}
			return rect;
		}	
		
		
		/**
		 * initialize the _textfield
		 * @param	width
		 * @param	height
		 * @param	type
		 */
		private function initTextField(width:Number, height:Number):void
		{
			_textfield = new TextField();
			_defaultFormat = new TextFormat(_fontName, _fontSize, _color, _bold, _italic, _underLine, null, null, null, null, null, true, _leading);
			//_defaultFormat.align =TextFormatAlign.LEFT;
			_textfield.defaultTextFormat=_defaultFormat;
			
			//_textfield.defaultTextFormat = new TextFormat("宋体",12,null,null,null,null,null,null,null,null,null,null,3);	
			_textfield.width = width;
			_textfield.height = height;
			_textfield.y = 5;
			//default multiline and wordWrap are true
			_textfield.multiline = true;
			_textfield.wordWrap = true;
			//for test view
			//_textfield.border = true;			
			//restriction of inserting placeholder
			_textfield.restrict = "^" + PLACEHOLDER;
		}
		
		/**
		 * create a mask of _spriteContainer
		 * @param	x
		 * @param	y
		 * @param	width
		 * @param	height
		 * @return
		 */
		private function createSpritesMask(x:Number, y:Number, width:Number, height:Number):Shape
		{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(0xFF0000);
			shape.graphics.lineStyle(0, 0x000000);
			shape.graphics.drawRect(x, y, width, height);
			shape.graphics.endFill();
			return shape;
		}
		
		/**
		 * adjust sprite's coordinate from beginIndex to endIndex
		 * @param	beginIndex
		 * @param	endIndex
		 */
		private function adjustCoordinate(beginIndex:int = -1, endIndex:int = -1):void
		{			
			for (var i:int = 0, len:int = _spriteContainer.numChildren; i < len; i++)
			{
				var sprite:Sprite = _spriteContainer.getChildAt(i) as Sprite;
				var spriteIndex:int = int(sprite.name);
				if (beginIndex <= spriteIndex && endIndex >= spriteIndex)
				{
					var rectPlaceholder:Rectangle = getCharBoundaries(spriteIndex);
					//trace("adjustCoordinate", sprite, spriteIndex, rectPlaceholder);
					if (rectPlaceholder) setSpriteCoordinate(sprite, rectPlaceholder);
				}
			}
		}
		/**
		 * 重写设置visible方法,解决在隐藏RichTextField时，表情容器不会隐藏的Bug.
		 * @copyright flex.joelove.cn
		 * @author WarmC (warm.cai@gmail.com)
		 * */
		override public function set visible(value:Boolean):void{
			_spriteContainer.visible=value;
			super.visible=value;
		}
		
		// ********************** getters & setters ********************************
		
		public function get numSprite():int
		{
			return _spriteContainer.numChildren;
		}
		
		public function getSpriteIndexAt(depth:int):int
		{			
			var sprite:Sprite = getSpriteAt(depth);
			if (sprite) 
				return int(sprite.name);
			else 
				return -1;
		}
		
		public function getSpriteAt(depth:int):Sprite
		{
			if (depth >= _spriteContainer.numChildren) 
				return null;
			return _spriteContainer.getChildAt(depth) as Sprite;
		}
		

		public static function hasNoImage(msg:String):Boolean
		{
			
			for(var i:int = 0;i<msg.length - 2;i++)
			{
				if(msg.charAt(i)=="/"&&imgstrToClass(msg.substr(i,3)))
				{
					return false;
				}
			}
			return true;
		}
		
//		public function set textHeight(value:int):void
//		{
//			this.height = value;
//			_textfield.height = value;
//			_textfield.defaultTextFormat = new TextFormat("宋体",12,null,null,null,null,null,null,null,null,null,null,3);	
//			this.scrollRect = new Rectangle(0, 0, height, value);
//		}
		
		public function resize(width:Number, height:Number):void
		{
			_textfield.width = _spriteMask.width = width;
			_textfield.height = _spriteMask.height = height;			
			adjustCoordinate(0, _textfield.length);
		}
		
		/**
		 * TextField实例。
		 */
		public function get textfield():TextField 
		{ 
			return _textfield;
		}
		
//		[Embed( "../../res/images/face/bx.png" )]
//		private static const bx : Class;
//		[Embed( "../../res/images/face/bd.png" )]
//		private static const bd : Class;
//		[Embed( "../../res/images/face/ws.png" )]
//		private static const ws : Class;
//		[Embed( "../../res/images/face/cj.png" )]
//		private static const cj : Class;
//		[Embed( "../../res/images/face/ks.png" )]
//		private static const ks : Class;
//		[Embed( "../../res/images/face/cy.png" )]
//		private static const cy : Class;
//		[Embed( "../../res/images/face/db.png" )]
//		private static const db : Class;
//		[Embed( "../../res/images/face/gh.png" )]
//		private static const gh : Class;
//		[Embed( "../../res/images/face/ll.png" )]
//		private static const ll : Class;
//		[Embed( "../../res/images/face/wy.png" )]
//		private static const wy : Class;
//		[Embed( "../../res/images/face/kx.png" )]
//		private static const kx : Class;
//		[Embed( "../../res/images/face/xh.png" )]
//		private static const xh : Class;
//		[Embed( "../../res/images/face/bs.png" )]
//		private static const bs : Class;
//		[Embed( "../../res/images/face/jo.png" )]
//		private static const jo : Class;
//		[Embed( "../../res/images/face/gx.png" )]
//		private static const gx : Class;
//		[Embed( "../../res/images/face/kb.png" )]
//		private static const kb : Class;
//		[Embed( "../../res/images/face/hx.png" )]
//		private static const hx : Class;
//		[Embed( "../../res/images/face/nu.png" )]
//		private static const nu : Class;
//		[Embed( "../../res/images/face/fh.png" )]
//		private static const fh : Class;
//		[Embed( "../../res/images/face/qt.png" )]
//		private static const qt : Class;
//		[Embed( "../../res/images/face/qq.png" )]
//		private static const qq : Class;
//		[Embed( "../../res/images/face/sd.png" )]
//		private static const sd : Class;
//		[Embed( "../../res/images/face/tu.png" )]
//		private static const tu : Class;
//		[Embed( "../../res/images/face/ts.png" )]
//		private static const ts : Class;
//		[Embed( "../../res/images/face/wx.png" )]
//		private static const wx : Class;
//		[Embed( "../../res/images/face/lm.png" )]
//		private static const lm : Class;
//		[Embed( "../../res/images/face/xn.png" )]
//		private static const xn : Class;
//		[Embed( "../../res/images/face/xs.png" )]
//		private static const xs : Class;
//		[Embed( "../../res/images/face/ye.png" )]
//		private static const ye : Class;
//		[Embed( "../../res/images/face/yu.png" )]
//		private static const yu : Class;
//		[Embed( "../../res/images/face/zu.png" )]
//		private static const zu : Class;
//		[Embed( "../../res/images/face/kl.png" )]
//		private static const kl : Class;
//		[Embed( "../../res/images/face/sj.png" )]
//		private static const sj : Class;
		public static function imgstrToClass(imgstr:String):Class
		{
			switch ( imgstr )
			{
//				case "/bx" : 
//					return bx;
//				case "/bd" :
//					return bd;
//				case "/sj" : 
//					return sj;
//				case "/kl" :
//					return kl;
//				case "/zu" :
//					return zu;
//				case "/yu" :
//					return yu;
//				case "/ye" :
//					return ye;
//				case "/xs" :
//					return xs;
//				case "/xn" : 
//					return xn;
//				case "/lm" :
//					return lm;
//				case "/wx" : 
//					return wx;
//				case "/ts" :
//					return ts;
//				case "/tu" :
//					return tu;
//				case "/sd" :
//					return sd;
//				case "/qq" :
//					return qq;
//				case "/qt" :
//					return qt;
//				case "/fh" : 
//					return fh;
//				case "/nu" :
//					return nu;
//				case "/hx" : 
//					return hx;
				case "/ku" :
//					return ku;
//				case "/kb" :
//					return kb;
//				case "/gx" :
//					return gx;
//				case "/jo" :
//					return jo;
//				case "/bs" :
//					return bs;
//				case "/xh" :
//					return xh;
//				case "/kx" : 
//					return kx;
//				case "/wy" :
//					return wy;
//				case "/ll" :
//					return ll;
//				case "/gh" :
//					return gh;
//				case "/db" :
//					return db;
//				case "/cy" :
//					return cy;
//				case "/ks" :
//					return ks;
//				case "/cj" :
//					return cj;
//				case "/ws" :
//					return ws;
			}
			return null;
		}
		
//		public function classToImgstr(dfs:String):String
//		{
//			dfs = dfs.substr(dfs.indexOf("Logo"),5);
//			switch ( dfs )
//			{
//				case "bx" : 
//					return "/bx";
//				case "bd" :
//					return "/bd";
//				case "sj" : 
//					return "/sj";
//				case "kl" :
//					return "/kl";
//				case "zu" :
//					return "/zu";
//				case "yu" :
//					return "/yu";
//				case "ye" :
//					return "/ye";
//				case "xs" :
//					return "/xs";
//				case "xn" : 
//					return "/xn";
//				case "lm" :
//					return "/lm";
//				case "wx" : 
//					return "/wx";
//				case "ts" :
//					return "/ts";
//				case "tu" :
//					return "/tu";
//				case "sd" :
//					return "/sd";
//				case "qq" :
//					return "/qq";
//				case "qt" :
//					return "/qt";
//				case "fh" : 
//					return "/fh";
//				case "nu" :
//					return "/nu";
//				case "hx" : 
//					return "/hx";
//				case "ku" :
//					return "/ku";
//				case "kb" :
//					return "/kb";
//				case "gx" :
//					return "/gx";
//				case "jo" :
//					return "/jo";
//				case "xh" :
//					return "/xh";
//				case "kx" : 
//					return "/kx";
//				case "wy" :
//					return "/wy";
//				case "ll" :
//					return "/ll";
//				case "gh" :
//					return "/gh";
//				case "db" :
//					return "/db";
//				case "cy" :
//					return "/cy";
//				case "ks" :
//					return "/ks";
//				case "cj" :
//					return "/cj";
//				case "/ws" :
//					return "/ws";
//			}
//			return null;
//		}

//		[Embed(source="../../res/images/bg/bgnull.png")]
//		private static const bgnull : Class;
//		[Embed(source="../../res/images/main/btn149_2.png",scaleGridLeft="4",scaleGridTop="15",scaleGridRight="5",scaleGridBottom="18")]
//		private static const btn1492 : Class;
//		[Embed(source="../../res/images/main/btn149_1.png",scaleGridLeft="4",scaleGridTop="15",scaleGridRight="5",scaleGridBottom="18")]
//		private static const btn1491 : Class;
//		[Embed(source="../../res/images/main/btn148_1.png")]
//		private static const btn1481 : Class;
//		[Embed(source="../../res/images/main/btn148_2.png")]
//		private static const btn1482 : Class;
//		[Embed(source="../../res/images/main/btn148_3.png")]
//		private static const btn1483 : Class;
//		[Embed(source="../../res/images/main/btn147_1.png")]
//		private static const btn1471 : Class;
//		[Embed(source="../../res/images/main/btn147_2.png")]
//		private static const btn1472 : Class;
//		[Embed(source="../../res/images/main/btn147_3.png")]
//		private static const btn1473 : Class;
//		public function getUIScrollBar():UIScrollBar
//		{
//			var scrollBar:UIScrollBar = new UIScrollBar();
//			scrollBar.setStyle("trackUpSkin", bgnull);
//			scrollBar.setStyle("trackOverSkin", bgnull);
//			scrollBar.setStyle("trackDownSkin", bgnull);
//			scrollBar.setStyle("trackDisabledSkin", bgnull);		
//			
//			scrollBar.setStyle("thumbUpSkin", btn1491);
//			scrollBar.setStyle("thumbOverSkin", btn1492);
//			scrollBar.setStyle("thumbDownSkin", btn1491);
//					
//			scrollBar.setStyle("downArrowUpSkin", btn1481);
//			scrollBar.setStyle("downArrowOverSkin", btn1482);
//			scrollBar.setStyle("downArrowDownSkin", btn1483);
//			scrollBar.setStyle("downArrowDisabledSkin", btn1481);
//			
//			scrollBar.setStyle("upArrowUpSkin", btn1471);
//			scrollBar.setStyle("upArrowOverSkin", btn1472);
//			scrollBar.setStyle("upArrowDownSkin", btn1473);
//			scrollBar.setStyle("upArrowDisabledSkin", btn1471);
//			return scrollBar;
//		}
	}	
}